//
//  FreeManagersViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/26.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "FreeManagersViewModel.h"
#import "FreeManagersTableViewCell.h"

@interface FreeManagersViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
}

@end

@implementation FreeManagersViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        CGFloat t_height;
        if (iPhoneX) {
            t_height = kHeightProportion_In_iPhoneTriploid(12) + 83;
        } else {
            t_height = kHeightProportion_In_iPhoneTriploid(44) + 49;
        }
        tableView.height = tableView.height - t_height;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.estimatedRowHeight = 20;
        tableView.rowHeight = UITableViewAutomaticDimension;
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        [superView addSubview:tableView];
        selfTableView = tableView;
    }
    return self;
}

#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FreeManagersTableViewCell *cell = [FreeManagersTableViewCell cellWithTableView:tableView];
    kWeakSelf(self);
    cell.BlockCall = ^(GLGWButton *callBtn) {
        [weakself leftAction:callBtn];
    };
    cell.BlockInput = ^(GLGWButton *callInput) {
        [weakself ritAction:callInput];
    };
    return cell;
}

- (void)leftAction:(GLGWButton *)sender
{
    if (self.BlockCall) {
        self.BlockCall(sender);
    }
}

- (void)ritAction:(GLGWButton *)sender
{
    if (self.BlockInput) {
        self.BlockInput(sender);
    }
}

@end
